#!/usr/bin/env python
# coding=utf-8
"""
# @Created on : 2016/05/01 15:08
# @Author     : ldf (ldf@eehello.com)
# @Link       : http://www.eehello.com
# @Version    : 
# 本程序在python2.7下测试通过
"""

import MySQLdb

def chaxun(toke):
    conn = MySQLdb.connect(host='10.41.4.230',user='root',passwd='12345',db='day5_zuoye',port=3306,charset='utf8')
    cur = conn.cursor()

    sql_cmd = "select name,time,data from talk_jl where toke=%s order by time"
    #print sql_cmd

    cur.execute(sql_cmd,(toke,))
    result = cur.fetchall()

    cur.close()
    conn.close()

    return result

def run(toke):
    a = chaxun(toke)
    with open('temp_talk', 'w') as fb:
        pass
    for d in a:

        #print d
        with open('temp_talk', 'a') as ff:
            ff.write(d[0]+':'+d[1]+'\n'+d[2]+'\n')

    with open('temp_talk', 'r') as fa:
        cc = fa.read()

    return cc


